// Package ioc
// Created by GoLand
// @User: lenora
// @Date: 2024/8/7
// @Time: 16:32

package ioc

import (
	"camp/microbook/constant"
	"camp/microbook/internal/job"
	"camp/microbook/internal/job/article"
	"camp/microbook/pkg/logger"
	"github.com/prometheus/client_golang/prometheus"
	"github.com/robfig/cron/v3"
)

func InitJobs(l logger.Logger, jobs []job.Job) *cron.Cron {
	c := cron.New(cron.WithSeconds())
	for _, j := range jobs {
		builder := job.NewCronJobBuilder(l, prometheus.SummaryOpts{
			Namespace:  constant.NAMESPACE,
			Subsystem:  constant.SUBSYSTEM,
			Name:       "cron_job_" + j.Name(),
			Objectives: constant.Objectives,
		})
		_, err := c.AddJob(j.Spec(), builder.Build(j))
		if err != nil {
			panic(err)
		}
	}
	return c
}

func InitJobGroup(rankingJob *article.RankingJob) []job.Job {
	return []job.Job{
		rankingJob,
	}
}
